package springbootcache.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import springbootcache.bean.Employee;

import java.net.UnknownHostException;

@Configuration
public class MyRedisConfig {


    @Bean
    public RedisTemplate<Object, Employee> emredisTemplate(RedisConnectionFactory redisConnectionFactory) throws UnknownHostException{
        RedisTemplate<Object, Employee> template = new RedisTemplate<Object, Employee>();
        Jackson2JsonRedisSerializer<Employee> ser = new Jackson2JsonRedisSerializer<Employee>(Employee.class);
        template.setDefaultSerializer(ser);

        template.setConnectionFactory(redisConnectionFactory);
        return template;
    }

    /*public RedisCacheManager employeeCacheManager(RedisTemplate<Object, Employee> emredisTemplate){
        RedisCacheManager cacheManager = new RedisCacheManager(emredisTemplate);

        return cacheManager;
    }*/
}
